package ACWing.acwing每日一题._5993回文数组;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int[] t = new int[n/2];
        for (int i = 0; i < n / 2; i++) {
            t[i] = a[n-1-i] - a[i];
        }
        long ans = 0;
        // 判断相邻的
        for (int i = 1; i < t.length ; i++) {
            if(t[i]>0&&t[i-1]>0){
                int c = Math.min(t[i],t[i-1]);
                ans+=c;
                t[i]-=c;t[i-1]-=c;
            }else if(t[i]<0&&t[i-1]<0){
                int c = -Math.max(t[i],t[i-1]);
                ans+=c;
                t[i]+=c;t[i-1]+=c;
            }
        }
        // 单个
        for (int j : t) {
            ans += Math.abs(j);
        }
        System.out.println(ans);
        scanner.close();
    }
}
